<?php
getHeader();
?>
<div id="content">
<div class="tabs headTabs">
<ul>
<?php
$comp = compProf::getCompetitionByCid((int)$_GET['cid']);
if (isset($_GET['cid']) && isset($_SESSION['authPassed']))
{
	$person = userProf::getUserByUid($_SESSION['uid']);
	if ($person->competitionStatus($_GET['cid']) != "NO")
	{
		echo "<li><span class='TabLink'>已加入</span></li>";
		echo "<li><a href='?p=viewTeam&cid={$_GET['cid']}' class='tabLink'>比赛队伍</a></li>";
	}
	else
	{
		if (isset($_GET['do']) && $_GET['do'] == 'join')
		{
			if ($person->competitionJoin($_GET['cid']))
			{
				echo "<li><span class='TabLink'>已加入</span></li>";
				echo "<li><a href='?p=viewTeam&cid={$_GET['cid']}' class='tabLink'>比赛队伍</a></li>";
			}
			else
			{
				echo "<li><span class='TabLink'>加入失败</span></li>";
			}
		}
		else
		{
			echo "<li><a href='?p=viewCompetition&cid={$_GET['cid']}&do=join' class='TabLink'>点击加入</a></li>";
		}
	}
	if ($person->uid == $comp->admin)
	{
		echo "<li><a href='?p=editCompetition&cid={$_GET['cid']}' class='TabLink'>编辑比赛</a></li>";
	}
}
?>
</ul>
<span>比赛信息</span></div>
<?php
if (!isset($_GET['cid']))
{
	echo "<div class='dataList'><span>请指定一个比赛进行查看.</span></div></div>";
}
else
{
	?>
<div class="dataList">
<ul>
	<li>
	<h2>比赛名称: <?php echo $comp->name; ?></h2>
	</li>
	<li>
	<h4>比赛描述: <?php echo $comp->description; ?></h4>
	</li>
	<li>
	<p>比赛状态: <?php echo $comp->readableStatus(); ?></p>
	</li>
	<li>
	<p>比赛宣传图片:</p>
	<ul class="albumList">
	<?php
	$result = $comp->getCompetitionImage();
	if ($result == "NO")
	{
		echo "<li>暂无图片</li>";
	}
	else
	{
		while ($i = mysql_fetch_array($result))
		{
			?>
		<a href='?p=viewImage&iName=<?php echo $i['imageName']; ?>'>
		<li><img src='<?php echo UPLOADURL.$i['imageName']; ?>'><br />
		<span><?php echo substr($i['imageName'],6,strripos($i['imageName'], '.') - 6); ?></span>
		</li>
		</a>
		<?php
		}
	}
	?>
		<li style="clear: both; float: none;"></li>
	</ul>
	</li>
</ul>
</div>
<div class="tabs headTabs"><?php
if (isset($_SESSION['uid']) && $_SESSION['uid'] == $comp->admin)
{
	?>
<ul>
	<li><a
		href='?p=editPost&do=add&group=<?php echo $comp->name; ?>&cid=<?php echo $comp->cid; ?>&type=official'
		class='TabLink'>添加资料</a></li>
</ul>
	<?php
}
?> <span>比赛资料</span></div>
<div class="dataList">
<ul>
<?php
$post = $comp->getCompetitionPost($status='static');
if ($post != 'NO')
{
	while ($arr = mysql_fetch_array($post))
	{
		?>
	<li><a href='?p=viewPost&pid=<?php echo $arr['pid']; ?>'><?php echo $arr['postName']; ?></a></li>
	<?php
	}
	?>
	<li style="clear: both; float: none;"></li>
	<?php
}
else
{
	echo '<li>本比赛暂无资料</li>';
}
?>
</ul>
</div>
<div class="tabs headTabs">
<ul>
	<li><a
		href='?p=editPost&do=add&group=<?php echo $comp->name; ?>&cid=<?php echo $comp->cid; ?>&type=discuss'
		class='tabLink'>创建讨论</a></li>
</ul>
<span>比赛讨论</span></div>
<div class="dataList">
<ul>
<?php
$post = $comp->getCompetitionPost('open');
if ($post == 'NO')
{
	echo "<li>本比赛暂无讨论</li>";
}
else
{
	while ($arr = mysql_fetch_array($post))
	{
		echo "<li><a href='?p=viewPost&pid={$arr['pid']}'>{$arr['postName']}</a></li>";
	}
}
?>
	<li style="clear: both; float: none;"></li>
</ul>
</div>
</div>
<?php
}
getPanel();
getFooter();
?>